<template>
	<view class="page" @touchstart="touchStart" @touchmove.capture="touchMove"
			@touchend="touchEnd">
		<swiper class="swiper" :current="current">
			<swiper-item @touchmove.stop="()=>{return false}" v-for="item,index in list" :key="index">
				<image :src="rq.imgUrl(item.image)" mode="aspectFill" class="syimg1"></image>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				current: 0,
				startX:null,
				endX:null,
				isSwipe:false,
				threshold:50,
			}
		},
		onLoad() {
			this.rq.getData('index/guide').then(res => {
				this.list = res.data.banner
			})
		},
		methods: {
			touchStart(e) {	
				console.log(e)
				this.startX = e.touches[0].clientX;
			},
			//触摸移动
			touchMove(e) {
				e.stopPropagation()
				console.log(e)
				this.endX = e.touches[0].clientX;
				this.isSwipe = true; //有触发移动
			},
			//触摸结束
			touchEnd(e) {
				if (!this.isSwipe) {
					return;
				} //没有滑动。防止误碰触发
				this.isSwipe = false;
				let distance = this.endX - this.startX;
				if (Math.abs(distance) > this.threshold) {
					// 判断滑动方向
					if (distance > 0 && this.current > 0) {
						this.current--;
					} else if (this.current < this.list.length - 1) {
						this.current++;
					} else if(this.current == this.list.length - 1){ 
						uni.setStorageSync('showGuide',true)
						uni.reLaunch({
							url:'/subpages/login/login'
						})
					}
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.page {
		min-height: 100vh;
	}

	.swiper {
		height: 100vh;

		.syimg1 {
			height: 100%;
			width: 100%;
		}
	}
</style>